Unit BDijitWidgetUnit;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, BDojoSessionUnit;

Type

{ BDijitW
idgetClass }

 { BDijitWidgetClass }

 BDijitWidgetClass = Class(BDojoObjectClass)
  Private
    bClosable: Boolean;
    bColSpan: Integer;
    bColumn: String;
    bCSSClass: String;
    bDir: String;
    bFieldLabel: String;
    bIconClass: String;
    bID: String;
    bLayoutAlign: String;
    bLayoutPriority: Integer;
    bMinSize: Integer;
    bRegion: String;
    bSelected: Boolean;
    bShowTitle: Boolean;
    bSlideFrom: String;
    bSpanLabel: String;
    bSplitter: Boolean;
    bStyle: String;
    bTitle: String;
    bTooltip: String;
    Procedure SetClosable(aValue: Boolean);
    Procedure SetColSpan(aValue: Integer);
    Procedure SetColumn(aValue: String);
    Procedure SetCSSClass(aValue: String);
    Procedure SetDir(aValue: String);
    Procedure SetFieldLabel(aValue: String);
    Procedure SetIconClass(aValue: String);
    Procedure SetID(aValue: String);
    Procedure SetLayoutAlign(aValue: String);
    Procedure SetLayoutPriority(aValue: Integer);
    Procedure SetMinSize(aValue: Integer);
    Procedure SetRegion(aValue: String);
    Procedure SetSelected(aValue: Boolean);
    Procedure SetShowTitle(aValue: Boolean);
    Procedure SetSlideFrom(aValue: String);
    Procedure SetSpanLabel(aValue: String);
    Procedure SetSplitter(aValue: Boolean);
    Procedure SetStyle(aValue: String);
    Procedure SetTitle(aValue: String);
    Procedure SetTooltip(aValue: String);
  Public
    //** HTML class attribute
    Property CSSClass: String Read bCSSClass Write SetCSSClass;
    //** Parameter for children of dijit.layout.StackContainer or subclasses.
    //** True if user can close (destroy) this child, such as (for example)
    //** clicking the X on the tab.
    Property Closable: Boolean Read bClosable Write SetClosable;
    //** The number of columns this widget should span.
    Property ColSpan: Integer Read bColSpan Write SetColSpan;
    //** Column of the grid to place the widget.
    //** Defined only if dojo.require("dojox.layout.GridContainerLite") is done.
    Property Column: String Read bColumn Write SetColumn;
    //** Bi-directional support, as defined by the
    //** [HTML DIR](http://www.w3.org/TR/html401/struct/dirlang.html#adef-dir)
    //** attribute. Either left-to-right "ltr" or right-to-left "rtl".
    //** If undefined, widgets renders in page's default direction.
    Property Dir: String Read bDir Write SetDir;
    //** Parameter for children of dijit.layout.StackContainer or subclasses.
    //** CSS Class specifying icon to use in label associated with this pane.
    Property IconClass: String Read bIconClass Write SetIconClass;
    //** A unique, opaque ID string that can be assigned by users or by the
    //** system. If the developer passes an ID which is known not to be unique,
    //** the specified ID is ignored and the system-generated ID is used instead.
    Property ID: String Read bID Write SetID;
    //** The label to display for a given widget
    Property FieldLabel: String Read bFieldLabel Write SetFieldLabel;
    //** layoutAlign "none", "left", "right", "bottom", "top", and "client".
    //** See the LayoutContainer description for details on this parameter.
    Property LayoutAlign: String Read bLayoutAlign Write SetLayoutAlign;
    //** Parameter for children of dijit.layout.BorderContainer.
    //** Children with a higher layoutPriority will be placed closer to the
    //** BorderContainer center, between children with a lower layoutPriority.
    Property LayoutPriority: Integer Read bLayoutPriority
      Write SetLayoutPriority;
    //** Parameter for children of dijit.layout.BorderContainer. Specifies
    //** a minimum size (in pixels) for this widget when resized by a splitter.
    Property MinSize: Integer Read bMinSize Write SetMinSize;
    //** Parameter for children of dijit.layout.BorderContainer.
    //** Values: "top", "bottom", "leading", "trailing", "left", "right",
    //** "center". See the dijit.layout.BorderContainer description for details.
    Property Region: String Read bRegion Write SetRegion;
    //** Parameter for children of dijit.layout.StackContainer or subclasses.
    //** Specifies that this widget should be the initially displayed pane.
    //** Note: to change the selected child use
    //** dijit.layout.StackContainer.selectChild
    Property Selected: Boolean Read bSelected Write SetSelected;
    //** Parameter for children of dijit.layout.StackContainer or subclasses.
    //** When true, display title of this widget as tab label etc., rather than
    //** just using icon specified in iconClass
    Property ShowTitle: Boolean Read bShowTitle Write SetShowTitle;
    //** Parameter needed by RadioGroupSlide only. An optional paramter to force
    //** the ContentPane to slide in from a set direction. Defaults to "random",
    //** or specify one of "top", "left", "right", "bottom" to slideFrom top,
    //** left, right, or bottom.
    Property SlideFrom: String Read bSlideFrom Write SetSlideFrom;
    //** Setting spanLabel to true makes the widget take up both the label and
    //** value cells. Defaults to false.
    Property SpanLabel: String Read bSpanLabel Write SetSpanLabel;
    //**  Parameter for child of dijit.layout.BorderContainer where
    //** region != "center". If true, enables user to resize the widget by
    //** putting a draggable splitter between this widget and the region=center
    //** widget.
    Property Splitter: Boolean Read bSplitter Write SetSplitter;
    //* HTML style attributes as cssText string or name/value hash
    Property Style: String Read bStyle Write SetStyle;
    //** HTML title attribute. For form widgets this specifies a tooltip to
    //** display when hovering over the widget (just like the native HTML title
    //** attribute). For TitlePane or for when this widget is a child of a
    //** TabContainer, AccordionContainer, etc., it's used to specify the tab
    //** label, accordion pane title, etc.
    Property Title: String Read bTitle Write SetTitle;
    //**  When this widget's title attribute is used to for a tab label,
    //** accordion pane title, etc., this specifies the tooltip to appear when
    //** the mouse is hovered over that text.
    Property Tooltip: String Read bTooltip Write SetTooltip;


    //TODO: add Ajax connection
    //** Connects specified obj/event to specified method of this object and
    //** registers for disconnect() on widget destroy.
    Procedure Connect(Const aObj: BDojoObjectClass;
      Const aEvent: String; Const aMethod: String);
    //TODO: disconnect
    //disconnect(handles) Disconnects handle created by connect.
    // Also removes handle from this widget's list of connects.
    //** Get a property from a widget.
    Function GetAttr(Const aParam, aName: String): String;
    //** Set a property on a widget
    Procedure SetAttr(Const aName, aValue: String);
    //** Set a property by object on a widget
    Procedure SetAttr(Const aName: String; Const aValue: BDijitWidgetClass);
    //** Processing after the DOM fragment is added to the document
    Procedure Startup;
    //** Returns a string that represents the widget
    Function ToString(Const aParam: String): String;
    //** Watches a property for changes
    Procedure Watch(Const aName: String; Const aJSCallback: String);
End;

Implementation

{ BDijitWidgetClass }

Procedure BDijitWidgetClass.SetClosable(aValue: Boolean);
Begin
  bClosable := aValue;
  SetConfig('closable', aValue);
End;

Procedure BDijitWidgetClass.SetColSpan(aValue: Integer);
Begin
  bColSpan := aValue;
  SetConfig('colspan', aValue);
End;

Procedure BDijitWidgetClass.SetColumn(aValue: String);
Begin
  bColumn := aValue;
  SetConfig('column', aValue);
End;

Procedure BDijitWidgetClass.SetCSSClass(aValue: String);
Begin
  bCSSClass := aValue;
  SetConfig('class', aValue);
End;

Procedure BDijitWidgetClass.SetDir(aValue: String);
Begin
  bDir := aValue;
  SetConfig('dir', aValue);
End;

Procedure BDijitWidgetClass.SetFieldLabel(aValue: String);
Begin
  bFieldLabel := aValue;
  SetConfig('label', aValue);
End;

Procedure BDijitWidgetClass.SetIconClass(aValue: String);
Begin
  bIconClass := aValue;
  SetConfig('iconClass', aValue);
End;

Procedure BDijitWidgetClass.SetID(aValue: String);
Begin
  bID := aValue;
  SetConfig('id', aValue);
End;

Procedure BDijitWidgetClass.SetLayoutAlign(aValue: String);
Begin
  bLayoutAlign := aValue;
  SetConfig('layoutAlign', aValue);
End;

Procedure BDijitWidgetClass.SetLayoutPriority(aValue: Integer);
Begin
  bLayoutPriority := aValue;
  SetConfig('layoutPriority', aValue);
End;

Procedure BDijitWidgetClass.SetMinSize(aValue: Integer);
Begin
  bMinSize := aValue;
  SetConfig('minSize', aValue);
End;

Procedure BDijitWidgetClass.SetRegion(aValue: String);
Begin
  bRegion := aValue;
  SetConfig('region', aValue);
End;

Procedure BDijitWidgetClass.SetSelected(aValue: Boolean);
Begin
  bSelected := aValue;
  SetConfig('selected', aValue);
End;

Procedure BDijitWidgetClass.SetShowTitle(aValue: Boolean);
Begin
  bShowTitle := aValue;
  SetConfig('showTitle', aValue);
End;

Procedure BDijitWidgetClass.SetSlideFrom(aValue: String);
Begin
  bSlideFrom := aValue;
  SetConfig('slideFrom', aValue);
End;

Procedure BDijitWidgetClass.SetSpanLabel(aValue: String);
Begin
  bSpanLabel := aValue;
  SetConfig('spanLabel', aValue);
End;

Procedure BDijitWidgetClass.SetSplitter(aValue: Boolean);
Begin
  bSplitter:=aValue;
  SetConfig('splitter', aValue);
End;

Procedure BDijitWidgetClass.SetStyle(aValue: String);
Begin
  bStyle:=aValue;
  SetConfig('style', aValue);
End;

Procedure BDijitWidgetClass.SetTitle(aValue: String);
Begin
  bTitle := aValue;
  SetConfig('title', aValue);
End;

Procedure BDijitWidgetClass.SetTooltip(aValue: String);
Begin
  bTooltip:=aValue;
  SetConfig('tooltip', aValue);
End;

Procedure BDijitWidgetClass.Connect(Const aObj: BDojoObjectClass;
  Const aEvent: String; Const aMethod: String);
Begin
  AddAjax('connect(%s, "%s", "%s");', [aObj.JSName, aEvent, aMethod]);
End;

Function BDijitWidgetClass.GetAttr(Const aParam, aName: String): String;
Begin
  Result := RequestParam(aParam, 'get("%s")', [aName]);
End;

Procedure BDijitWidgetClass.SetAttr(Const aName, aValue: String);
Begin
  AddAjax('set("%s", "%s");', [aName, aValue]);
End;

Procedure BDijitWidgetClass.SetAttr(Const aName: String;
  Const aValue: BDijitWidgetClass);
Begin
  AddAjax('set("%s", %s);', [aName, aValue.JSName]);
End;

Procedure BDijitWidgetClass.Startup;
Begin
  AddAjax('startup();');
End;

Function BDijitWidgetClass.ToString(Const aParam: String): String;
Begin
  Result := RequestParam(aParam, 'toString()');
End;

Procedure BDijitWidgetClass.Watch(Const aName: String;
  Const aJSCallback: String);
Begin
  AddAjax('watch("%s", function(){%s});', [aName, aJSCallback]);
End;


End.

